//
//  JXRecommendController.m
//  JiaoX
//
//  Created by yinqy on 15/1/22.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//




#import "JXRecommendController.h"
#import "SelfDataTool.h"
#import "RecomdItemCell.h"

@interface JXRecommendController (){
    NSMutableArray *_dataArray;
}

@end


@implementation JXRecommendController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"精品推荐"];
    _dataArray = [NSMutableArray array];
    [self requestData];
    [self.tableView setTableFooterView:[[UIView alloc]init]];
}

-(void)requestData{
    MBProgressHUD *HUD = [DialogUtils showLoadingWithView:self.navigationController.view];
    [SelfDataTool getRecommendAppList:^(RemndAppList *result) {
        [HUD hide:YES];
        if ([Utils isBlankString:result.data]) {
            [_dataArray addObjectsFromArray:result.appList];
            [self.tableView reloadData];
        }else{
            [DialogUtils showTipsWithView:self.navigationController.view String:result.data];
        }
        
    } failure:^(NSError *error) {
        [HUD hide:YES];
        [DialogUtils showTipsWithView:self.navigationController.view String:@"加载失败"];
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RecomdItemCell *cell = [RecomdItemCell cellWithTableView:tableView];
    [cell.reComdItemView setComdApp:_dataArray[indexPath.row]];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return RECOMD_ITEM_VIEW_HEIGHT;
}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [Utils setSeparatorInsetWithTableView:self.tableView insets:UIEdgeInsetsMake(0, JXPublicInset, 0, 0)];
}



@end
